package com.yundasys.lab12java.java8;

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 * @PACKAGE_NAME: com.yundasys.lab12java.java8
 * @NAME: DateTest
 * @USER: jiangta
 * @DATE: 2021/7/28
 * @TIME: 9:00 上午
 * @PROJECT_NAME: springboot-labs
 */
public class DateTest {

    public static void main(String[] args) {
        //本周周一
        LocalDateTime with = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).with(DayOfWeek.MONDAY);
        System.out.println(with);

        //上周周一
        LocalDateTime localDateTime = LocalDateTime.of(LocalDate.now(), LocalTime.MIN).with(DayOfWeek.MONDAY).minusWeeks(1);
        System.out.println(localDateTime);

        //计算时间差
        LocalDateTime startTime = LocalDateTime.now().plusDays(-7);
        LocalDateTime endTime = LocalDateTime.now();
        Duration between = Duration.between(startTime, endTime);
        System.out.println(between.toDays());
        System.out.println(between.toHours());

        //format yyyy-MM-dd HH:mm:ss
        LocalDateTime dateTime = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dateTime.format(dateTimeFormatter);
        System.out.println(format);

    }
}